package com.faklyn.bootcommon.web.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIgnoreType;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * web响应实体 - response result
 * @author ronghl
 * @date 2021-02-07
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
@AllArgsConstructor
public class RespResult<T> {
    private int code;
    private String msg;
    private T data;

    @JsonIgnore
    public boolean isSuccess() {
        return code == 200;
    }

    public static RespResult success() {
        return success(null);
    }

    public static RespResult success(Object data) {
        return success("ok", data);
    }

    public static RespResult success(String msg, Object data) {
        return new RespResult(200, msg, data);
    }

    public static RespResult fail(String msg) {
        return fail(msg, null);
    }

    public static RespResult fail(int code, String msg) {
        return fail(code, msg, null);
    }

    public static RespResult fail(String msg, Object data) {
        return fail(201, msg, data);
    }

    public static RespResult fail(int code, String msg, Object data) {
        return new RespResult(code, msg, data);
    }

}
